﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using vwsol_DuHoc.Areas.Administrator.Models;

namespace vwsol_DuHoc.Areas.Administrator.Controllers
{
    public class AdminClassController : Controller
    {
        //
        // GET: /Administrator/AdminClass/

        public ActionResult Index(string message = "", string level = "")
        {
            try
            {
                if (level == "Success")
                {
                    ViewBag.Success = message;
                }
                if (level == "Warning")
                {
                    ViewBag.Warning = message;
                }
                if (level == "Error")
                {
                    ViewBag.Error = message;
                }
                using (AdminVwsolDbDataContext db = new AdminVwsolDbDataContext())
                {
                    List<Class_GetAllResult> model = new List<Class_GetAllResult>();
                    model = db.Class_GetAll().ToList();
                    return View(model);
                }
            }
            catch (Exception)
            {
                ViewBag.Error = "Lỗi lấy dữ liệu lớp học!";
                List<Class_GetAllResult> model = new List<Class_GetAllResult>();
                return View(model);
            }
        }

        public ActionResult CreateClass()
        {
            using (AdminVwsolDbDataContext db = new AdminVwsolDbDataContext())
            {
                Class model = new Class();
                ViewData["CourseList"] = db.Courses.Where(m => m.IsDelete == false).OrderBy(m => m.CourseName).ToList();
                ViewData["TeacherList"] = db.Teachers.Where(m => m.IsDelete == false).OrderBy(m => m.TeacherName).ToList();
                return View(model);
            }
        }

    }
}
